
// 定义用户模块中的数据
export default {
    namespaced: true, //可选 设置命名空间,注册了当前模块
    state: {
        userinfo: {
            username: '张义山',
            age: 27
        },
        count: 100000
    },
    mutations: {
        editAge(state) {
            state.userinfo.age += 1
        },
        editName(state, payload) {
            state.userinfo.username = payload
        },
        addCount(state) {
            state.count += 1000
        }

    },
    actions: {
        editAgeAsync({ commit }) {
            setTimeout(() => {
                commit('editAge')
            }, 2000)
        }

    },
    getters: {
        doubleAgeUser(state) {
            return {
                ...state.userinfo,
                age: state.userinfo.age * 2
            }
        }

    }
}